package com.bindapp.model;

import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.GridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;

import com.bindapp.R;
import com.bindapp.activity.ControllerAmoActivity;
import com.bindapp.activity.ControllerCdActivity;
import com.bindapp.activity.ControllerHcActivity;
import com.bindapp.activity.ControllerJsActivity;
import com.bindapp.activity.ControllerPaoActivity;
import com.bindapp.activity.ControllerPhpActivity;
import com.bindapp.activity.ControllerPsActivity;
import com.bindapp.activity.ControllerSWActivity;
import com.bindapp.activity.ControllerSclActivity;
import com.bindapp.adapter.GridAdapter;
import com.bindapp.databinding.ActivityDevicedetailBinding;
import com.bindapp.listener.RecyclerItemClick;
import com.bindapp.util.Static;
import com.bindapp.widget.GridDecoration;
import com.youth.banner.listener.OnBannerListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by apple on 2018/7/1.
 */

public class DeviceModel extends BaseModel {

    private GridAdapter adapter;
    private List<Object> datalist;
    private ActivityDevicedetailBinding binding;


    public DeviceModel(Context context){
        super(context);
        binding= DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.activity_devicedetail,null,false);

        datalist=new ArrayList<Object>();
        for(int i=0;i<11;i++){
            datalist.add(""+i);
        }
        adapter=new GridAdapter(context,datalist,R.layout.item_device_detail,-1,new ItemClick(),new BannerClick());
        adapter.addHeadView(R.layout.item_device_head);
        binding.recycleview.addItemDecoration(new GridDecoration(context,5,3,true));
        GridLayoutManager layoutManage = new GridLayoutManager(context, 3);
        layoutManage.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup(){

            @Override
            public int getSpanSize(int position) {
                if(position==0){
                   return 3;
                }
                return 1;
            }
        });
        binding.recycleview.setLayoutManager(layoutManage);
        binding.recycleview.setAdapter(adapter);
    }


    class BannerClick implements OnBannerListener {

        @Override
        public void OnBannerClick(int position) {
            Static.showToast(context,""+position);

        }
    }

    class ItemClick implements RecyclerItemClick{

        @Override
        public void onItemClick(int position) {
            Intent intent=null;
            switch (position){
                case 1:
                    intent=new Intent(context, ControllerSWActivity.class);
                    context.startActivity(intent);
                    break;
                case 2:
                    intent=new Intent(context, ControllerPhpActivity.class);
                    context.startActivity(intent);
                    break;
                case 3:
                    intent=new Intent(context, ControllerPaoActivity.class);
                    context.startActivity(intent);
                    break;
                case 4:
                    intent=new Intent(context,ControllerPaoActivity.class);
                    context.startActivity(intent);
                    break;
                case 5:
                    intent=new Intent(context, ControllerSclActivity.class);
                    context.startActivity(intent);
                    break;
                case 6:
                    intent=new Intent(context, ControllerAmoActivity.class);
                    context.startActivity(intent);
                    break;
                case 7:
                    intent=new Intent(context,ControllerAmoActivity.class);
                    context.startActivity(intent);
                    break;
                case 8:
                    intent=new Intent(context, ControllerCdActivity.class);
                    context.startActivity(intent);
                    break;
                case 9:
                    intent=new Intent(context, ControllerJsActivity.class);
                    context.startActivity(intent);
                    break;
                case 10:
                    intent=new Intent(context, ControllerPsActivity.class);
                    context.startActivity(intent);
                    break;
                case 11:
                    intent=new Intent(context, ControllerHcActivity.class);
                    context.startActivity(intent);
                    break;
            }

        }

        @Override
        public void onItemLongClick(int position) {

        }

        @Override
        public void onMoreClick(View view, int position) {

        }
    }

    @Override
    public ActivityDevicedetailBinding getBinding() {
        return binding;
    }

}
